1886A - Sum of Three - CodeForces Solution


brute force math

Please click on ads to support us..

C++ Code:

//edu_r156_a.cpp
#include<bits/stdc++.h>
using namespace std;

int main(){
	/*ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);*/
	int t;cin>>t;
	while(t--){
		int n;cin>>n;
		bool flg=1;
		if(n<=6||n==9){
			flg=0;
			cout<<"NO"<<"\n";
		}
		if(flg){
			cout<<"YES"<<endl;
			if(n==7){
				cout<<"1 2 4"<<"\n";
			}
			else if(n==8){
				cout<<"1 2 5"<<"\n";
			}
			else{
				int xx,yy,zz;
				int val=n/3;
				int le=n-3*val;
				if(le==0){
					xx=1;
					yy=3+1;
					zz=3*(val-1)-2;
					cout<<xx<<" "<<yy<<" "<<zz<<"\n";
				}
				else{
					xx=le;
					yy=3+1;
					zz=3*(val-1)-1;
					cout<<xx<<" "<<yy<<" "<<zz<<"\n";
				}
			}
		}
		
	}
	return 0;
}

//7


//8
//1 2 5
//11
//1 2 8

//17
//1 2 14
//19
//1 2 16

//10
//1 2 7
//
//if n/3能整除
// n/3+5 n/3-1 n/3-4

//21
//2 8 11

//12
//1 2 10

//if n/3不能整除
//剩下1
//n/3+1 n/3+2 n/3-2

//剩下2
//n/3+2 n/3+1 n/3-1


Comments

Submit
0 Comments
More Questions

931A - Friends Meeting
1594A - Consecutive Sum Riddle
1466A - Bovine Dilemma
454A - Little Pony and Crystal Mine
2A - Winner
1622B - Berland Music
1139B - Chocolates
1371A - Magical Sticks
1253A - Single Push
706B - Interesting drink
1265A - Beautiful String
214A - System of Equations
287A - IQ Test
1108A - Two distinct points
1064A - Make a triangle
1245C - Constanze's Machine
1005A - Tanya and Stairways
1663F - In Every Generation
1108B - Divisors of Two Integers
1175A - From Hero to Zero
1141A - Game 23
1401B - Ternary Sequence
598A - Tricky Sum
519A - A and B and Chess
725B - Food on the Plane
154B - Colliders
127B - Canvas Frames
107B - Basketball Team
245A - System Administrator
698A - Vacations